---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Distribution of departments by aisles for less than 4 days since prior order
```{r}
data("instacart")
instacart_3 = instacart %>%
filter(days_since_prior_order < 4,
department %in% c("bakery", "snacks", "canned goods")) %>%
arrange(aisle, department) %>%
plot_ly(
x = ~department, y = ~aisle, type = "scatter", mode = "markers",
color = ~days_since_prior_order, alpha = 0.5)
```
Column {data-width=350}
-----------------------------------------------------------------------
### Number of items ordered in each aisle >20000
```{r}
data("instacart")
instacart_1 = instacart %>%
count(aisle) %>%
arrange(desc(n)) %>%
filter(n > 20000) %>%
mutate(aisle = fct_reorder(aisle, n)) %>%
plot_ly(x = ~aisle, y = ~n, color = ~aisle, type = "bar", colors = "viridis")
```
### The mean hour of the day at which top 3 most frequently ordered products are ordered
```{r}
data("instacart")
instacart_2 = instacart %>%
filter(product_name %in% c("Banana", "Bag of Organic Bananas", "Organic Strawberries")) %>%
group_by(product_name, order_dow) %>%
summarize(mean_hour = mean(order_hour_of_day)) %>%
arrange(product_name, order_dow, mean_hour) %>%
mutate(product_name = fct_reorder(product_name, mean_hour)) %>%
plot_ly(y = ~mean_hour, color = ~product_name, type = "box", colors = "viridis")
```